<template>
  <Layout type="Home" @getScroll="getScroll">
    <div class="home">
      <!-- home-banner -->
      <div class="fixed-search" :style="fixedSearchStyle">
        <div class="search" @click="handleSearch">
          <span class="font_family icon-sousuo"></span
          ><span class="text">报工、服务单等</span>
        </div>
      </div>
      <div class="home-banner">
        <div class="search" @click="handleSearch">
          <span class="font_family icon-sousuo"></span
          ><span class="text">报工、服务单等</span>
        </div>
        <div v-if="indexData" class="user-info">
          <div class="info">
            <div class="info-name">{{ indexData.user.nameinfo }}</div>
            <div class="info-base">
              <div class="name">{{ indexData.user.name }}</div>
              <div class="department">{{ indexData.user.department }}</div>
            </div>
          </div>
          <div class="message" @click="$router.push('/service/serviceType?type=1')">
            <div class="num">{{ indexData.numbers.need_deal_number }}</div>
            <div class="desc">我的待办</div>
          </div>
        </div>
      </div>
      <!-- message-list -->
      <div v-if="indexData" class="message-list">
        <!-- TODO 这里要添加跳转 -->
        <div class="item" @click="$router.push('/service/serviceType?type=2')">
          <div class="num">{{ indexData.numbers.need_read_number }}</div>
          <div class="desc">我的待阅</div>
        </div>
        <div class="item" @click="$router.push('/service/serviceType?type=3')">
          <div class="num">{{ indexData.numbers.join_number }}</div>
          <div class="desc">我的参与</div>
        </div>
        <div class="item" @click="$router.push('/service/serviceType?type=4')">
          <div class="num">{{ indexData.numbers.finish_number }}</div>
          <div class="desc">已办结</div>
        </div>
      </div>
      <!-- home-service -->
      <div v-if="indexData" class="home-service">
        <div class="home-title">
          <div class="title">
            IT服务单
            <!-- <img src="@/assets/svg/xinjian.svg" class="add" @click="$router.push('/service/detail')"/> -->
          </div>
          <div class="more" @click="$router.push('/service')">
            更多<span class="font_family icon-gengduo"></span>
          </div>
        </div>
        <div class="service-menu">
          <div class="item color1" @click="$router.push('/service?type=1')">
            <div class="info">
              <div class="num">{{indexData.numbers.my_process_number}}</div>
              <div class="desc">我的服务单</div>
            </div>
            <img src="@/assets/svg/wode.svg" class="img" />
          </div>
          <div class="item color2" @click="$router.push('/service?type=2')">
            <div class="info">
              <div class="num">
                {{ indexData.numbers.group_process_number }}
              </div>
              <div class="desc">团队服务单</div>
            </div>
            <img src="@/assets/svg/tuandui.svg" class="img" />
          </div>
        </div>
      </div>
      <!-- home-ol -->
      <div class="home-ol">
        <div class="home-title">
          <div class="title">
            报工管理<img
              src="@/assets/svg/xinjian.svg"
              class="add"
              @click="$router.push('/ol/detail')"
            />
          </div>
          <div class="more" @click="$router.push('/ol')">
            更多<span class="font_family icon-gengduo"></span>
          </div>
        </div>
        <div v-if="report" class="home-ol-container">
          <div class="home-ol-menu">
            <div class="list">
              <div
                class="item"
                :class="olStatus == 'my' ? 'active' : ''"
                @click="olStatus = 'my'"
              >
                我的报工
              </div>
              <div
                class="item"
                :class="olStatus == 'audit' ? 'active' : ''"
                @click="olStatus = 'audit'"
              >
                报工审批
              </div>
            </div>
            <!-- <div class="more">
              <span class="font_family icon-gengduo"></span>
            </div> -->
          </div>
          <div
            v-for="(item, index) in report"
            :key="index"
            class="home-ol-item"
            @click="godetail(item.id)"
          >
            <div class="info">
              <div class="title">{{ item.title }}</div>
              <div class="time">{{ item.report_date }}</div>
            </div>
            <div class="more-info">
              <div class="desc">{{ item.project_name }}</div>
              <div class="hour">{{ item.time }}</div>
            </div>
            <div class="status">
              <p v-if="olStatus == 'my'">
                {{ item.is_plan == 1 ? "计划内" : "计划外" }}
              </p>
              <p v-else>{{ item.name }}</p>
              <span v-if="olStatus == 'audit' && item.status == 2">待审核</span>
              <span v-if="olStatus == 'audit' && item.status == 3">已审核</span>
              <span v-if="olStatus == 'audit' && item.status == 4"
                >审核未通过</span
              >
            </div>
          </div>
        </div>
      </div>
      <!-- home-declaration -->
      <div class="home-declaration">
        <div class="home-title">
          <div class="title">报表平台</div>
          <div class="more" @click="$router.push('/declaration')">
            更多<span class="font_family icon-gengduo"></span>
          </div>
        </div>
        <!-- <van-swipe :loop="false" :show-indicators='false' :width="300">
          <van-swipe-item>
            <div class="home-table">
          <div class="home-table-title">
            <div class="title">IT服务单提数报表</div>
            <div class="desc">详情</div>
          </div>
          <div class="table-data">
            <div class="name">张国寿</div>
            <div class="line">
              <div class="over-line" style="width: 60%">余6h</div>
              <div class="diver"></div>
            </div>
          </div>
          <div class="table-data">
            <div class="name">李四</div>
            <div class="line over">
              <div class="over-line">超1h</div>
              <div class="diver"></div>
            </div>
          </div>
          <div class="table-data">
            <div class="name">张国寿</div>
            <div class="line">
              <div class="over-line" style="width: 60%">余6h</div>
              <div class="diver"></div>
            </div>
          </div>
          <div class="table-data">
            <div class="name">李四</div>
            <div class="line over">
              <div class="over-line">超1h</div>
              <div class="diver"></div>
            </div>
          </div>
        </div>
          </van-swipe-item>
          <van-swipe-item>2</van-swipe-item>
          <van-swipe-item>3</van-swipe-item>
          <van-swipe-item>4</van-swipe-item>
        </van-swipe> -->
        <div class="platform">
          <p v-for="(item,index) in indexData.tables" :key="index" @click="statement(item.name)">{{item.name}}</p>
        </div>
      </div>
      <!-- over -->
      <div class="home-over">已经到底啦～</div>
    </div>
    <quit></quit>
  </Layout>
</template>
<script>
import Layout from "@/layout";
import { home } from "@/api/home.js";
import Quit from "@/components/quit"
export default {
  name: "Home",
  components: {
    Layout,
    Quit
  },
  data() {
    return {
      olStatus: "my",
      fixedSearchStyle: "opacity: 0",
      indexData: "",
      report: "", //报工
      
    };
  },
  mounted() {
    this.getData();
    
  },
  watch: {
    olStatus(newVal) {
      if (newVal == "my") {
        this.report = this.indexData.report_manage.report;
      } else {
        this.report = this.indexData.report_manage.approval;
      }
    },
  },
  methods: {
    handleSearch() {
      this.$router.push("/search");
    },
    getScroll(val) {
      if (val > 100) {
        this.fixedSearchStyle = "opacity: 1";
      } else {
        let opacity = val / 100;
        this.fixedSearchStyle = `opacity: ${opacity}`;
      }
    },
    getData() {
      home().then((res) => {
        console.log(res);
        if (res.status == "success") {
          res.data.user.nameinfo = res.data.user.name.slice(0, 1);
          this.indexData = res.data;
          this.report = res.data.report_manage.report;
        }
      });
    },
    godetail(id) {
      if (this.olStatus == "my") {
        this.$router.push({
          path: "/ol/detail",
          query: {
            id: id,
          },
        });
      } else {
        this.$router.push({
          path: "/ol/audit",
          query: {
            id: id,
          },
        });
      }
    },

    //报表平台
    statement(name){
      this.$router.push({
          path: "/Declaration",
          query: {
            name: name,
          },
        });
    }
  },
};
</script>
<style lang="less" scoped>
.home {
  background: #f7f9f9;
  min-height: calc(100vh - (60px + env(safe-area-inset-bottom)));
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.fixed-search {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 15px;
  background: #fff;
  z-index: 100;
  .search {
    // margin: 0 15px;
    background: #f8f8f8;
    border-radius: 7px;
    height: 37px;
    line-height: 37px;
    padding-left: 14px;
    .icon-sousuo {
      font-size: 16px;
      color: #8f92a1;
    }
    .text {
      font-size: 13px;
      margin-left: 8px;
      color: #8f92a1;
      opacity: 0.7;
    }
  }
}
.home-banner {
  background-image: url("../assets/home_bg@2x.png");
  height: 181px;
  padding-top: 15px;
  background-size: cover;
  .search {
    margin: 0 15px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 7px;
    height: 37px;
    line-height: 37px;
    padding-left: 14px;
    .icon-sousuo {
      font-size: 16px;
      color: #fff;
    }
    .text {
      font-size: 13px;
      margin-left: 8px;
      color: #fff;
      opacity: 0.7;
    }
  }
  .user-info {
    display: flex;
    margin: 30px 15px 0;
    .info {
      position: relative;
      display: flex;
      flex: 1;
      padding-top: 15px;
      padding-left: 5px;
      &::after {
        position: absolute;
        content: "";
        top: 17px;
        right: 0;
        width: 1px;
        height: 41px;
        background: #fff;
        opacity: 0.5;
      }
      .info-name {
        position: relative;
        font-size: 17px;
        color: #009966;
        line-height: 51px;
        text-align: center;
        width: 51px;
        height: 51px;
        background: #ffffff;
        border-radius: 50%;
        &::after {
          position: absolute;
          top: -5px;
          left: -5px;
          width: 59px;
          height: 59px;
          border-radius: 50%;
          border: 1px solid rgba(255, 255, 255, 0.5);
          content: "";
          background: transparent;
        }
      }
      .info-base {
        margin-left: 13px;
        width: calc(100% - 77px);
      }
      .name {
        font-size: 19px;
        font-weight: bold;
        color: #fff;
      }
      .department {
        margin-top: 3px;
        font-size: 14px;
        color: #fff;
        opacity: 0.8;
      }
    }
    .message {
      width: 98px;
    }
    .num {
      font-size: 47px;
      font-weight: bold;
      text-align: center;
      color: #fff;
    }
    .desc {
      font-size: 15px;
      text-align: center;
      color: #fff;
    }
  }
}
// message-list
.message-list {
  display: flex;
  background: #fff;
  height: 57px;
  .item {
    flex: 1;
    color: #313541;
    .num {
      margin-top: 9px;
      font-size: 17px;
      font-weight: bold;
      text-align: center;
    }
    .desc {
      font-size: 12px;
      text-align: center;
    }
  }
}
// home-title
.home-title {
  display: flex;
  .title {
    flex: 1;
    font-size: 17px;
    line-height: 20px;
    font-weight: bold;
    color: #313541;
  }
  .add {
    width: 21px;
    vertical-align: middle;
    margin-left: 10px;
    margin-top: -2px;
  }
  .more {
    font-size: 12px;
    line-height: 20px;
    color: #8f92a1;
    span {
      font-size: 12px;
    }
  }
}
// home-service
.home-service {
  margin: 28px 15px 0;
  .service-menu {
    display: flex;
    margin-top: 15px;
    .item {
      display: flex;
      width: calc((100vw - 39px) / 2);
      height: 110px;
      border-radius: 9px;
      justify-content: center;
      align-items: center;
      &.color1 {
        background: #e8f1ff;
      }
      &.color2 {
        background: #dbf4eb;
      }
      &:first-child {
        margin-right: 9px;
      }
    }
    .info {
      display: flex;
      flex-direction: column;
      padding-left: 15px;
      flex: 1;
      .num {
        font-size: 22px;
        font-weight: bold;
        color: #313541;
      }
      .desc {
        font-size: 13px;
        color: #313541;
      }
    }
    .img {
      width: 42px;
      margin-right: 6px;
    }
  }
}
// home-ol
.home-ol {
  margin: 26px 15px 0;
  .home-ol-container {
    margin-top: 15px;
    background: #ffffff;
    border-radius: 7px;
  }
  .home-ol-menu {
    display: flex;
    height: 37px;
    padding: 0 15px;
    line-height: 37px;
    border-bottom: 1px solid #f7f9f9;
    .list {
      flex: 1;
      display: flex;
    }
    .item {
      position: relative;
      font-size: 13px;
      color: #313541;
      margin-right: 22px;
      &.active {
        font-weight: bold;
        color: #009966;
        &:after {
          position: absolute;
          left: 50%;
          bottom: 0;
          content: "";
          width: 20px;
          margin-left: -10px;
          height: 1px;
          background: #009966;
        }
      }
    }
    .more {
      width: 30px;
      text-align: right;
      span {
        font-size: 13px;
      }
    }
  }
  .home-ol-item {
    // height: 67px;
    color: #313541;
    margin: 0 15px;
    border-bottom: 4px solid #f7f9f9;
    &:last-child {
      border-bottom: 0;
    }
    .info {
      display: flex;
      padding-top: 14px;
      .title {
        flex: 1;
        height: 22px;
        font-size: 16px;
        font-weight: bold;
        line-height: 22px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .time {
        width: 80px;
        height: 22px;
        line-height: 22px;
        color: #939dad;
        font-size: 12px;
        text-align: right;
      }
    }
    .more-info {
      display: flex;
      margin-top: 6px;
      margin-bottom: 10px;
      .desc {
        flex: 1;
        font-size: 12px;
        height: 17px;
        line-height: 17px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .hour {
        width: 50px;
        height: 17px;
        line-height: 17px;
        font-size: 17px;
        font-weight: bold;
        color: #009966;
        text-align: right;
      }
    }
    .status {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      border-top: 1px solid #f2f2f2;
      padding: 6px 0px;
      p {
        color: #313541;
        font-size: 13px;
        margin: 0;
      }
      span {
        color: #0041c4;
        font-size: 13px;
      }
    }
  }
}
// home-declaration
.home-declaration {
  margin: 26px 15px 0;
  .home-table {
    background: #fff;
    border-radius: 7px;
    margin-top: 15px;
    padding-bottom: 1px;
    .home-table-title {
      display: flex;
      padding: 0 15px;
      line-height: 37px;
      height: 37px;
      border-bottom: 1px solid #f2f2f2;
    }
    .title {
      flex: 1;
      font-size: 14px;
      color: #313541;
    }
    .desc {
      font-size: 12px;
      color: #8f92a1;
    }
  }
  .table-data {
    display: flex;
    padding: 0 15px;
    font-size: 12px;
    margin: 18px 0;
    .name {
      width: 60px;
      color: #011445;
    }
    .over-line {
      height: 15px;
      background: #009966;
      color: #ffffff;
      border-radius: 3px;
      text-align: right;
      padding-right: 10px;
      box-sizing: border-box;
    }
    .diver {
      position: absolute;
      left: 70%;
      top: 0;
      height: 15px;
      width: 1px;
      background: #d2d5d5;
    }
    .line {
      position: relative;
      flex: 1;
      height: 15px;
      border-radius: 3px;
      background: #f7f9f9;
      &.over {
        .over-line {
          background: #e6b522;
        }
        .diver {
          background: #fff;
        }
      }
    }
  }
  .platform {
    background: #ffffff;
    border-radius: 8px;
    padding: 0 16px;
    margin-top: 16px;
    p {
      padding: 18px 0;
      border-bottom: 4px solid #f7f9f9;
      color: #313541;
      font-size: 17px;
      font-weight: 600;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      word-break: break-all;
      margin: 0;
      &:last-child {
        border-bottom: 0;
      }
    }
  }
}
// home-over
.home-over {
  font-size: 12px;
  color: #939dad;
  margin-top: 30px;
  text-align: center;
}
</style>